package com.eastfair.datasync.listener;

import com.alibaba.fastjson.JSONObject;
import com.eastfair.datasync.entity.CanalData;
import com.eastfair.datasync.enumeration.MysqlBusinessEnum;
import com.eastfair.datasync.util.CanalUtil;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public abstract class SyncAbstractOfJson  implements SyncInterfaceOfJson  {

    @Override
    public void executeAll(String message, JSONObject jsonObject) {
        CanalData<JSONObject> canalData = CanalUtil.parseDataOfJson(message);
        if(canalData==null){
            return;
        }
        log.info("executeAll message is {}", message);


        if(MysqlBusinessEnum.INSERT.eq(canalData.getMysqlBusinessEnum())){
            executeInsert(canalData);
        }else if(MysqlBusinessEnum.UPDATE.eq(canalData.getMysqlBusinessEnum())){
            executeUpdate(canalData);
        }else if(MysqlBusinessEnum.ALTER.eq(canalData.getMysqlBusinessEnum())){
            executeAlter(canalData);
        }else if(MysqlBusinessEnum.DELETE.eq(canalData.getMysqlBusinessEnum())){
            executeAlter(canalData);
        }
    }


}
